package basic.study.wantOffer.chapter5;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

/**
 * @ClassName Problem45
 * @Description 把数组排成最小的数
 * @Company inspur
 * @Author Kevin
 * @Date 2020/6/4 16:34
 * @Version 1.0
 */
public class Problem45 {
    class SortArrayForMinNumber {
        public String PrintMinNumber(int [] numbers) {
            if (numbers == null || numbers.length == 0) {
                return "";
            }
            ArrayList<String> list = new ArrayList<>();
            for (int num: numbers) {
                list.add(String.valueOf(num));
            }
            Collections.sort(list, new Comparator<String>() {
                @Override
                public int compare(String o1, String o2) {
                    String a = o1 + o2;
                    String b = o2 + o1;
                    return a.compareTo(b);
                }
            });
            StringBuilder sb = new StringBuilder();
            for (String l: list) {
                sb.append(l);
            }
            return sb.toString();
        }
    }
}
